package com.ark.controller.game;

import com.ark.common.domain.entity.game.GameConfig;
import com.ark.common.response.Result;
import com.ark.service.cache.GlobalGameConfigCache;
import com.ark.service.service.GameConfigService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @作者 Mr.Liu
 * @Date 2025/1/3 14:21
 * @version 1.0
 * @注释
 */
@RestController
@RequestMapping("/api/gameConfig")
public class GameConfigController {

    @Resource
    private GameConfigService gameConfigService;
    @Resource
    private GlobalGameConfigCache globalGameConfigCache;

    @RequestMapping("/info")
    public Result gameConfigTemplate(){

        return Result.success(globalGameConfigCache.getGameConfig());
    }

    @GetMapping("/refresh")
    public Result refresh(){
        globalGameConfigCache.refreshCache();
        return Result.success();
    }

    @GetMapping("/clear")
    public Result clear(){
        globalGameConfigCache.clearCache();
        return Result.success();
    }

    @PutMapping("/edit")
    public Result updateGameTemplate(@RequestBody GameConfig config){
        boolean update = gameConfigService.lambdaUpdate().update(config);
        if (!update){
            return Result.error();
        }
        return Result.success();
    }

}
